package com.ddwl.user.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.schema.bo.user.QueryUserLevelBo;
import com.ddwl.schema.vo.user.UserLevelVo;
import com.ddwl.user.dao.mapper.UserLevelMapper;
import com.ddwl.user.dao.model.User;
import com.ddwl.user.dao.model.UserLevel;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * UserLevelDao.java的实现描述：TODO
 *
 * @author wenbin
 */
@Repository
public class UserLevelDao extends TkDao<UserLevelMapper, UserLevel> {

    @Resource
    private UserLevelMapper userLevelMapper;

    /**
     * 获取用户等级列表
     * @return
     */
    public List<UserLevelVo> queryUserLevelList(QueryUserLevelBo bo) {
        Example example = getExample();
        example.and().andEqualTo("id", bo.getId())
                    .andEqualTo("userLevelCode",bo.getUserLevelCode());
        example.setOrderByClause(" user_level_code ");
        List<UserLevelVo> list = BeanConverUtils.convertBeanList(baseMapper.selectByExample(example),UserLevelVo.class);
        return list;
    }
    /**
     * 获取用户下一等级
     * @return
     */
    public List<UserLevelVo> getNextLevel(Integer userLevelCode) {
        Example example = getExample();
        example.and().andGreaterThanOrEqualTo("userLevelCode",userLevelCode);
        example.setOrderByClause(" user_level_code LIMIT 2 ");
        List<UserLevelVo> list = BeanConverUtils.convertBeanList(baseMapper.selectByExample(example),UserLevelVo.class);
        return list;
    }

    public void batchUpdateLevel(List<User> users) {
        baseMapper.batchUpdateLevel(users);
    }

    public List<UserLevel> getAll() {
        return userLevelMapper.selectAll();
    }

    public void changeId(Map<String, String> map) {
        userLevelMapper.changeId(map);
    }
}
